package com.cloudkinto.controller.wr;

import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.wr.QuotationSchemeService;
import com.cloudkinto.vo.wr.trial.LcCodeRes;
import com.cloudkinto.vo.wr.trial.TrialFreightRes;
import com.cloudkinto.vo.wr.trial.TrialOmpReq;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequiredArgsConstructor
@Api(tags = "运费试算omp模块")
@RequestMapping("/api/admin/omp/QuotationScheme")
public class TrialFreightOmpController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(TrialFreightOmpController.class);

    private final QuotationSchemeService service;


    @UserSessionRequired
    @GetMapping("/getLcForTrial")
    @ApiOperation(value = "运费试算-根据报价方案 获取物流渠道", notes = "运费试算-根据报价方案 获取物流渠道")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "quotationId", value = "报价方案id")
    })
    @ApiResponses(@ApiResponse(code = 200, message = "", response = LcCodeRes.class))
    public SingleResult getLcForTrial(HttpServletRequest request){
        String quotationId = request.getParameter("quotationId");
        return SingleResult.success("查询成功", service.getLcForTrial(StringUtils.isBlank(quotationId) ? null : Long.parseLong(quotationId), getTenantId()));
    }



    @UserSessionRequired
    @PostMapping("/trialFreight")
    @ApiOperation(value = "omp运费试算", notes = "omp运费试算")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TrialFreightRes.class))
    public SingleResult trialFreight(@RequestBody @Validated TrialOmpReq req) {
        return SingleResult.success(service.ompTrialFreightFee(req, getTenantId()));
    }
}
